package com.qihui.converter;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.qihui.bean.Point;

public class PointConverter2 extends StrutsTypeConverter {

	@SuppressWarnings("unchecked")
	@Override
	public Object convertFromString(Map arg0, String[] values, Class toClass) {
		Point point = new Point();
		String[] paramValues = values[0].split(",");
		int x = Integer.parseInt(paramValues[0]);
		int y = Integer.parseInt(paramValues[1]);

		point.setX(x);
		point.setY(y);
		return point;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String convertToString(Map arg0, Object o) {
		Point point = (Point) o;
		int x = point.getX();
		int y = point.getY();
		String result = "[x" + x + " , y=" + y + "]";
		return result;
	}

}
